<template>
    <view>
        <view v-if="detail != null" class="page_big padding-horizontal-main padding-top-main">
			<view v-if="detail.goods_type == 0 && (detail.order_model == 0 || detail.order_model == 2)" class="address bg-white padding-horizontal-main padding-top-main border-radius-main spacing-mb">
				<view class="address-base oh">
				    <text v-if="(detail.address_data.alias || null) != null" class="address-alias round br-main cr-main bg-white margin-right-sm">{{detail.address_data.alias}}</text>
				    <text>{{detail.address_data.name}}</text>
				    <text class="fr">{{detail.address_data.tel}}</text>
				</view>
				<view class="address-detail oh margin-bottom-main">
					<image class="icon fl" :src="scorestore_static_url+'mini/user-address.png'" mode="widthFix" />
					<view class="text fr">
						{{ detail.address_data.province_name }}{{ detail.address_data.city_name }}{{ detail.address_data.county_name }}{{ detail.address_data.address }}
						<text
							v-if="detail.order_model == 2 && (detail.address_data.lng || 0) > 0 && (detail.address_data.lat || 0) > 0"
							class="cr-666 br address-map-submit"
							@tap="address_map_event"
						>
							{{$t('user-order-detail.user-order-detail.7lp6gw')}}
						</text>
					</view>
				</view>
				<view class="address-divider spacing-mb"></view>
			</view>
			
            <view class="goods bg-white spacing-mb border-radius-main padding-default">
                <view class="goods-item oh" v-for="(item, index) in detail.items" :key="index">
                    <navigator :url="'/pages/fcc/scorestore/detail/detail?goods_id=' + item.goods_id" hover-class="none">
                        <image class="goods-image fl" :src="item.images" mode="aspectFill" />
                        <view class="goods-base">
                            <view class="goods-title multi-text">{{ item.title }}</view>
                            <block v-if="item.spec != null">
                                <view class="goods-attribute cr-888" v-for="(spec, index1) in item.spec" :key="index1">{{ spec.type }}:{{ spec.value }}</view>
                            </block>
                        </view>
                        <view class="oh goods-price">
                            <text class="sales-price">{{ item.price }}积分</text>
                            <text v-if="item.original_price > 0" class="original-price">￥{{ item.original_price }}</text>
                            <text class="buy-number">x{{ item.buy_number }}</text>
                        </view>
                    </navigator>
                </view>
            </view>
			
			<!-- 虚拟销售数据 -->
			<view v-if="detail.goods_type == 1 && detail.pay_status == 1 && (detail.status == 3 || detail.status == 4)" class="site-fictitious panel-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mb">
				<view class="br-b padding-bottom-main fw-b text-size">{{site_fictitious.title}}</view>
				<view class="panel-content oh padding-top-main">
					<view v-if="(site_fictitious.tips || null) != null" class="tips-value radius padding-main margin-bottom-main">
					    <mp-html :content="site_fictitious.tips" />
					</view>
					<view v-for="(item, index) in detail.items" :key="index" class="item br-b-dashed oh padding-bottom-main margin-bottom-main">
					    <image class="left-image br fl radius" :src="item.images" mode="aspectFill"></image>
					    <view class="right-value fr">
					        <view v-if="(item.spec_text || null) != null" class="text-grey padding-bottom-xs margin-bottom-xs br-b-f9 text-size-xs">{{item.spec_text}}</view>
					        <mp-html v-if="(item.fictitious_goods_value || null) != null" :content="item.fictitious_goods_value" />
					        <text v-else class="cr-grey">{{$t('user-order-detail.user-order-detail.7xtnjt')}}</text>
					    </view>
					</view>
				</view>
			</view>
			
			<!-- 自提信息 -->
			<view v-if="(detail.extraction_data || null) != null" class="site-extraction panel-item padding-main border-radius-main bg-white spacing-mb">
			    <view class="br-b padding-bottom-main fw-b text-size">{{$t('user-order-detail.user-order-detail.7dikfm')}}</view>
			    <view class="panel-content oh padding-top-main">
			        <image v-if="(detail.extraction_data.images || null) != null" class="qrcode br radius margin-bottom-sm" :src="detail.extraction_data.images" mode="aspectFill"></image>
			        <view>
			            <text>{{$t('user-order-detail.user-order-detail.o38952')}}</text>
			            <text class="radius bg-green cr-white padding-left-sm padding-right-sm">{{ detail.extraction_data.code || $t('user-order-detail.user-order-detail.hpq62x') }}</text>
			        </view>
			    </view>
			</view>
			
            <view v-if="detail_list.length > 0" class="detail-list bg-white border-radius-main padding-default">
                <view class="item br-b oh" v-for="(item, index) in detail_list" :key="index">
                    <view class="title fl br-r">{{ item.name }}</view>

                    <view class="content cr-888 fl">{{ item.value }}</view>
                </view>
            </view>
			
			<!-- 扩展数据 -->
			<view v-if="extension_data.length > 0" class="panel-item padding-main border-radius-main bg-white spacing-mb">
			    <view class="br-b padding-bottom-main fw-b text-size">{{$t('user-order-detail.user-order-detail.ct34n5')}}</view>
			    <view class="panel-content oh">
			        <view v-for="(item, index) in extension_data" :key="index" class="item br-b-dashed oh padding-vertical-main cr-base">
			            <text>{{ item.name }}</text>
			            <text v-if="(item.tips || null) != null">：{{ item.tips }}</text>
			        </view>
			    </view>
			</view>

            <component-bottom-line :prop-status="data_bottom_line_status"></component-bottom-line>
        </view>

        <view v-if="detail == null">
           <component-no-data :prop-status="data_list_loding_status" :prop-msg="data_list_loding_msg"></component-no-data>
        </view>

        <!-- 结尾 -->
        <component-footer :prop-status="3"></component-footer>
    </view>
</template>

<script>
import componentPopup from '@/components/popup/popup';
import componentIconNav from '@/components/icon-nav/icon-nav';
import componentBanner from '@/components/slider/slider';
import componentFooter from "@/pages/fcc/scorestore/public/footer";
import componentNoData from "@/components/no-data/no-data";
import componentBottomLine from "@/components/bottom-line/bottom-line";
import componentOnlineService from "@/components/online-service/online-service";
const app = getApp();
var scorestore_static_url = app.globalData.get_static_url('scorestore', true);
var common_static_url = app.globalData.get_static_url('common');
export default {
	components: {
	    componentPopup,
		componentIconNav,
		componentBanner,
		componentFooter,
		componentNoData,
		componentBottomLine,
		componentOnlineService
	},
    data() {
        return {
			scorestore_static_url:scorestore_static_url,
			common_static_url:common_static_url,
            detail: null,
            detail_list: [],
            data_list_loding_status: 1,
            data_list_loding_msg: '',
            data_bottom_line_status: false,
            params: null,
			extension_data: [],
			site_fictitious: null,
        };
    },
    onLoad(params) {
        this.setData({
            params: params
        });
        this.init();
    },
    onShow() {
        app.globalData.page_event_onshow_handle();
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.init();
    },
    methods: {
        init() {
            var self = this;
            uni.showLoading({
                title: this.$t('common.loading_in_text'),
            });
            this.setData({
                data_list_loding_status: 1
            });
            uni.request({
                url: app.globalData.get_request_url('orderdetail', 'index', 'scorestore'),
                method: 'POST',
                data: {
                    id: this.params.id
                },
                dataType: 'json',
                success: (res) => {console.log(res);
                    uni.hideLoading();
                    uni.stopPullDownRefresh();

                    if (res.data.code == 0) {
                        var data = res.data.data;
						var temp_detail_data_list = data.scorestore_common.order_detail_data_list_array || [];
						var order_model = parseInt(data.order_model);
						var goods_type = parseInt(data.goods_type);
						var is_express_show = true;
						var temp_detail = [];
						// 虚拟物品或者取货方式为自提的时候，不需要显示物流信息
						if(order_model == 2 || goods_type == 1)
						{
							is_express_show = false;
						}
						if(temp_detail_data_list.length > 0){
							for (var i in temp_detail_data_list) {
								if(temp_detail_data_list[i]['value'] == 'express_name')
								{
									if(is_express_show)
									{
										temp_detail.push(
											{ name: temp_detail_data_list[i]['name'], value: ((data[temp_detail_data_list[i]['value']] || null) != null) ? data[temp_detail_data_list[i]['value']] : '' }
										);
									}
								}else if(temp_detail_data_list[i]['value'] == 'express_number')
								{
									if(is_express_show)
									{
										temp_detail.push(
											{ name: temp_detail_data_list[i]['name'], value: ((data[temp_detail_data_list[i]['value']] || null) != null) ? data[temp_detail_data_list[i]['value']] : '' }
										);
									}
								}else{
									temp_detail.push(
										{ name: temp_detail_data_list[i]['name'], value: ((data[temp_detail_data_list[i]['value']] || null) != null) ? data[temp_detail_data_list[i]['value']] : '' }
									);
								}
							}
						}
                        self.setData({
                            detail: data,
                            detail_list: temp_detail,
                            data_list_loding_status: 3,
                            data_bottom_line_status: true,
                            data_list_loding_msg: '',
							site_fictitious: data.site_fictitious || null,
							extension_data: data.extension_data || [],
                        });
                    } else {
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: res.data.msg
                        });
                        app.globalData.showToast(res.data.msg);
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    self.setData({
                        data_list_loding_status: 2,
                        data_bottom_line_status: false,
                        data_list_loding_msg: this.$t('common.internet_error_tips')
                    });
                    app.globalData.showToast(this.$t('common.internet_error_tips'));
                }
            });
        },
		
		// 地图查看
		address_map_event(e) {
		    if ((this.detail.address_data || null) == null) {
		        app.globalData.showToast(this.$t('user-order-detail.user-order-detail.i876o3'));
		        return false;
		    }
		
		    // 打开地图
		    var data = this.detail.address_data;
		    var name = data.alias || data.name || '';
		    var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
		    app.globalData.open_location(data.lng, data.lat, name, address);
		},

        // 导航事件
        navigation_event(e) {
            app.globalData.operation_event(e);
        }
    }
};
</script>
<style>
@import './orderdetail.css';
</style>
